#ifndef UDPAPPENDER_H
#define UDPAPPENDER_H

#include <QUdpSocket>
#include <QRecursiveMutex>
#include <QStringConverter>
#include "baseappender.h"

//输出内容到网络UDP
//1.设置输出等级
//2.设置输出端口
class UdpAppender : public BaseAppender
{
    Q_OBJECT
public:
    UdpAppender(LogLevel level,
                QString strRemoteIp = "127.0.0.1",
                quint16  nRemotePort = 9009);
    ~UdpAppender();

    void setRemoteAddr(QString strIp,quint16 nPort);
    // 新增：设置发送编码（支持UTF-8、GBK等常见编码）
    void setEncoding(QStringConverter::Encoding encoding);
    void append(LogLevel level,const QString &msg) override;
private:
    QUdpSocket *m_Udp = nullptr;
    QString m_RemoteIp ="127.0.0.1";
    quint16  m_RemotePort=9009;
    QRecursiveMutex m_mutex;
    // 存储编码格式（默认系统编码）
    QStringConverter::Encoding m_encoding = QStringConverter::System;
};

#endif // UDPAPPENDER_H
